﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Core;

namespace SM2SetupSearch
{
    public class BulkUploadActions
    {
        public static void BulkUpload_SetTextInto_bulk_search_text(string strKeywords)
        {
            Utilities.GlobalObject.MANAGER.ActiveBrowser.RefreshDomTree();
            HtmlDiv pnlContent = Utilities.GlobalObject.MANAGER.ActiveBrowser.Find.ById<HtmlDiv>("pnlContent");
            HtmlDiv cphPageContent_mSearchWizard = pnlContent.Find.ById<HtmlDiv>("cphPageContent_mSearchWizard");
            HtmlDiv search_wizard_panel = cphPageContent_mSearchWizard.Find.ById<HtmlDiv>("search-wizard-panel");
            HtmlDiv search_setup = search_wizard_panel.Find.ById<HtmlDiv>("search-setup");
            HtmlForm create_search_form = search_setup.Find.ById<HtmlForm>("create-search-form");

            //Input keywords
            HtmlDiv final_bulk_search_wrapper = create_search_form.Find.ById<HtmlDiv>("final-bulk-search-wrapper");
            HtmlTextArea bulk_upload_search_text = final_bulk_search_wrapper.Find.ById<HtmlTextArea>("bulk-upload-search-text");
            
            //Prepare string to follow the way to input multiple line for bulk keywords
            string strInput = "";
            if (strKeywords.Contains(","))
                strInput = strKeywords.Replace(",", "\n");
            else strInput = strKeywords;
            SM2Input.Tradition.TypeTextIntoTextAreaWithHint(bulk_upload_search_text, strInput);
            System.Threading.Thread.Sleep(1000);
           
            //Hit Validate       
            HtmlDiv tabs_bulk_upload = create_search_form.Find.ById<HtmlDiv>("tabs-bulk-upload");
            HtmlDiv bulk_edit_validate = tabs_bulk_upload.Find.ById<HtmlDiv>("bulk-edit-validate");
            IList<HtmlAnchor> iListSubmit = bulk_edit_validate.Find.AllByAttributes<HtmlAnchor>();
            HtmlAnchor btn = iListSubmit[0];
            SM2Input.Tradition.ClickAnchor(btn);            
        }
    }
}
